package com.t2t.top.monitor;

import java.util.ArrayList;
import java.util.List;

/**
 * JConsole监视代码
 * <p/>
 * 内存占位符对象，一个OOMObject大约占64KB
 * <p/>
 * 参数：-Xms100m -Xmx100m -XX:+UseSerialGC
 * <p/>
 * 描述：64KB/50秒的速度往Java对中填充数据，一共填充1000次，使用JConsole的"内存"页标签进行监控，观察曲线和柱状变化
 */
class OOMObject {
    public byte[] placeholder = new byte[64 * 1024];
}

public class OOMObjectTest {
    public static void fillHeap(int num) throws InterruptedException {
        List<OOMObject> list = new ArrayList();
        for (int i = 0; i < num; i++) {
            //稍作延迟，令监视曲线变化的更加明显
            list.add(new OOMObject());
            Thread.sleep(50);
        }
    }

    public static void main(String[] args) throws InterruptedException {
        fillHeap(1000);
    }
}
